package cn.com.zsc.acr122u;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang.StringUtils;

public class ACR122UReaderServlet extends HttpServlet {

	/**
	 * 
	 */
	private static final long serialVersionUID = -2396009382408554747L;

	@Override
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {

		doPost(request, response);

	}

	@Override
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {

		response.setContentType("text/html;charset=UTF-8");
		request.setCharacterEncoding("UTF-8");
		response.setHeader("charset", "UTF-8");

		String newcardID = request.getParameter("newcardID");
		String queryflag = request.getParameter("query");
		String modifyflag = request.getParameter("modify");

		ACR122UReaderInfo info = new ACR122UReaderInfo();

		if (modifyflag != null && StringUtils.isNotBlank(newcardID)) {
			info.writeCardInfo(newcardID);
		}
		if (queryflag != null) {
			info.queryCardInfo();
		}

		response.sendRedirect("/ZSC/test/122cardinfo.jsp");
	}

}
